package eu.jba.denshijisho.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import eu.jba.denshijisho.R;
import eu.jba.denshijisho.entity.Note;

public class NoteDao extends AbstractDao<Note>{
	
	public static final String KEY_ROWID = "_id";
	public static final String KEY_ROW_ID_NAME = "id";
	public static final String KEY_NOTE = "note";
	public static final String KEY_NOTE_NAME = "Note";

	public NoteDao(Context ctx) {
		super(ctx);
	}	
	
	@Override
	protected int getCreateResource() {
		return R.raw.create_table_note;
	}

	@Override
	protected int getUpdateResource() {
		return R.raw.update_table_note;
	}

	@Override
	protected String getTableName() {
		return getContext().getResources().getString(R.database.NOTE_TABLE);
	}

	@Override
	protected ContentValues getInitialValues(Note object) {
		final ContentValues initialValues = new ContentValues();
		initialValues.put(KEY_NOTE, object.getNote());
		return initialValues;
	}

	@Override
	protected String getRowIdColumnName() {
		return KEY_ROWID;
	}

	@Override
	protected String[] getColumns() {
		return new String[] { KEY_ROWID, KEY_NOTE };
	}

	@Override
	protected Note convertTo(Cursor cursor) {
		final Note note = new Note(cursor.getInt(0), cursor.getString(1));
		return note;
	}

}
